package vip.xiaonuo.biz.modular.lancerBrand.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.pojo.domain.BizBrand;
import vip.xiaonuo.biz.modular.pojo.dto.add.BrandAddDTO;
import vip.xiaonuo.biz.modular.pojo.dto.common.CommonDeleteDTO;
import vip.xiaonuo.biz.modular.pojo.dto.common.CommonDetailDTO;
import vip.xiaonuo.biz.modular.pojo.dto.edit.BrandEditDTO;
import vip.xiaonuo.biz.modular.pojo.dto.edit.BrandEditStatusDTO;
import vip.xiaonuo.biz.modular.pojo.dto.page.BrandPageDTO;
import vip.xiaonuo.biz.modular.lancerBrand.service.BizBrandService;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * 管理员品牌控制器
 *
 * @author admin
 * @date 2024/01/02
 */
@Api(tags = "品牌管理(管理端)")
@ApiSupport(author = "LANCER_TEAM", order = 1)
@RestController
@RequestMapping
@Validated
public class AdminBrandController {

    @Autowired
    private BizBrandService brandService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("管理端品牌分页")
    @GetMapping("/biz/admin/brand/page")
    @SaCheckPermission("/biz/admin/brand/page")
    public CommonResult<Page<BizBrand>> page(@Valid BrandPageDTO dto) {
        Page<BizBrand> res = brandService.pageL(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("管理端品牌详情查询")
    @SaCheckPermission("/biz/admin/brand/detail")
    @GetMapping("/biz/admin/brand/detail")
    public CommonResult<BizBrand> detail(@Valid CommonDetailDTO dto) {
        BizBrand res = brandService.detail(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("管理端品牌新增")
    @PostMapping("/biz/admin/brand/add")
    @SaCheckPermission("/biz/admin/brand/add")
    public CommonResult<String> add(@Valid BrandAddDTO dto) {
        brandService.add(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("管理端品牌删除")
    @PostMapping("/biz/admin/brand/delete")
    @SaCheckPermission("/biz/admin/brand/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "删除id不能为空") List<CommonDeleteDTO> dto) {
        brandService.delete(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("管理端品牌编辑")
    @PostMapping("/biz/admin/brand/edit")
    @SaCheckPermission("/biz/admin/brand/edit")
    public CommonResult<String> edit(@Valid BrandEditDTO dto) {
        brandService.edit(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("管理端品牌状态变更")
    @PostMapping("/biz/admin/brand/edit/status")
    @SaCheckPermission("/biz/admin/brand/edit/status")
    public CommonResult<String> editStatus(@RequestBody @Valid BrandEditStatusDTO dto) {
        brandService.editStatus(dto);
        return CommonResult.ok();
    }
}